package org.huang.feign;

import feign.RequestLine;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;

/**
 * Created by fangzhipeng on 2017/4/6.
 */
@FeignClient(value = "eureka-client")
public interface SchedualServiceHi {

    @GetMapping(value = "/hello")
    String sayHiFromClientOne();

    @GetMapping(value = "/user/{username}/{age}")
    //坑1：必须加上@PathVariable("username") ，并且@PathVariable必须设置value
    //错误代码： User getUser1(@PathVariable String username, @PathVariable Integer age)
    User getUser1(@PathVariable("username") String username, @PathVariable("age") Integer age);


    //坑2：Get请求，不能省略@RequestParam("username"),并且@RequestParam必须设置value
    //错误代码：User getUser2(String username,Integer age);
    @GetMapping("/user")
    User getUser2(@RequestParam("username") String username, @RequestParam("age") Integer age);

    //坑3：Post请求，被调用的接口必须有@RequestBody参数，否则获取不到值！
    @PostMapping("/postUser")
    User getUser3(User user);

    //坑4： Get请求默认不支持复杂的对象传值
    /*
     解决方案一：
     1.添加配置信息
        feign:
          httpclient:
            enabled: true
     2. 添加feign-httpclient依赖
         <!-- 使用Apache HttpClient替换Feign原生httpclient -->
        <dependency>
            <groupId>com.netflix.feign</groupId>
            <artifactId>feign-httpclient</artifactId>
            <version>8.18.0</version>
        </dependency>
    3. @GetMapping 注解必须添加 consumes = "application/json"属性
    4. 被调用的接口必须有@RequestBody参数，否则获取不到值！
    解决方案二：
        使用Map传值
    解决方案三：
        一个一个的传值
     */
    @GetMapping(value = "/getUser",consumes = "application/json")
    User getUser4(User user);
}
